package xml;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.awt.Color;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;


import vnctest.TestConfig;

/**
 *
 * @author Uladzimir_Staliarou
 */
public class SAXHandler extends DefaultHandler {

    private TestConfig config;


    /**
     * @return the products
     */
    public TestConfig getConfig() {
        return config;
    }

    @Override
    public void startElement(String uri, String localName, String qName,
            Attributes attributes) throws SAXException {
        String aValue = attributes.getValue("value");
        switch (XMLTags.Tags.valueOf(qName.toUpperCase())) {
            case CONFIG: {
                config = new TestConfig();
                break;
            }
            case BACKGROUND: {
            	config.setBackground(aValue);
                break;
            }
            case TIMERINTERVAL: {
            	int result = Integer.parseInt(aValue);
            	config.setTimeInterval(result);
                break;
            }
            case COUNT: {
            	int result = Integer.parseInt(aValue);
            	config.setCount(result);
                break;
            }
            case COLOR: {
            	Color result = Color.decode(aValue);
            	config.setColor(result);
                break;
            }
            case HSIZE: {
            	Double result = Double.parseDouble(aValue);
            	config.sethSize(result);
                break;
            }
            case WSIZE: {
            	Double result = Double.parseDouble(aValue);
            	config.setwSize(result);
                break;
            }
            case SPEED: {
            	Double result = Double.parseDouble(aValue);
            	config.setSpeed(result);
                break;
            }
            case FIGURE: {
            	TestConfig.FigureType result = TestConfig.FigureType.valueOf(aValue);
            	config.setType(result);
                break;
            }
            default:
                break;
        }
    }

    @Override
    public void characters(char[] ch, int start, int length) throws SAXException {
    }

    @Override
    public void endElement(String uri, String localName,
            String qName) throws SAXException {
    }
}

